import * as cc from 'cc';
import { _decorator, Component, director, Node, sys, v2, v3 } from 'cc';
import { ISerializable, loadScene, saveScene } from './SaveLoadScene';
const { ccclass, property } = _decorator;

@ccclass('HealthTest')
export class HealthTest extends Component implements ISerializable {
    @property
    public health: number = 100;

    @property(cc.Label)
    label: cc.Label = null!;

    protected onLoad(): void {
        cc.input.on(cc.Input.EventType.KEY_DOWN, (e) => {
            if (e.keyCode === cc.KeyCode.KEY_S) {
                console.log('save');
                saveScene();
            }
        });

        cc.input.on(cc.Input.EventType.KEY_DOWN, (e) => {
            if (e.keyCode === cc.KeyCode.KEY_L) {
                console.log('load');
                loadScene();
            }
        });
    }

    serialize() {
        return {
            health: this.health,
        };
    }

    deserialize(data: any) {
        this.health = data.health;
    }

    update(deltaTime: number) {
        this.health += deltaTime;
        this.label.string = this.health.toFixed(1);
    }
}
